package com.orphan.supplier.mq;

import com.orphan.supplier.po.Back;
import com.orphan.supplier.po.Backgoods;
import com.orphan.supplier.service.IBackService;
import com.orphan.supplier.service.IBackgoodsService;
import com.orphan.util.dto.SupplierReturnDto;
import com.orphan.util.mqConfig.MQUtil;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 获取审核系统发过来的退货订单
 */
@Component
@RabbitListener(queues = {"queueaudit"})
public class BackMq {
    @Resource
    IBackService backService;
    @Resource
    IBackgoodsService backgoodsService;
    @Resource
    private MQUtil mqUtil;

    @RabbitHandler
    public void receive(SupplierReturnDto dto, Message message, Channel channel){
        System.out.println(dto);
        Back back=new Back();
        back.setTOrderId(dto.getTOrderId());
        back.setTOrderTime(dto.getTOrderTime());
        back.setTSupplierName(dto.getTSupplierName());
        back.setTState(dto.getTState());
        back.setTTotal(dto.getTTotal());
        Backgoods backgoods=new Backgoods();
        backgoods.setTGoodsname(dto.getSupplierGoods().get(0).getGoodsName());
        backgoods.setTGoodstype(dto.getSupplierGoods().get(0).getType());
        backgoods.setTPrice(dto.getSupplierGoods().get(0).getPrice());
        backgoods.setTGoodsnum(dto.getSupplierGoods().get(0).getGoodsNum());
        backgoods.setTSize(dto.getSupplierGoods().get(0).getSize());
        backgoods.setTFkId(dto.getSupplierGoods().get(0).getTFkId());
        backService.addBackOrder(back);
        backgoodsService.addgoods(backgoods);
        mqUtil.ack(message,channel);
    }
}
